package cn.com.css.taxInspection.zdgz.controller;

import cn.com.css.taxInspection.common.aop.annotation.LogAnnotation;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.zdgz.entity.GzcbEntity;
import cn.com.css.taxInspection.zdgz.service.GzcbService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.List;

/**
 * 重点关注-关注查补
 */
@RequestMapping("/gzcb")
@RestController
@Api(tags = "关注查补")
public class GzcbController {

    private final GzcbService gzcbService;

    private final HttpSessionService httpSessionService;

    public GzcbController(GzcbService gzcbService, HttpSessionService httpSessionService) {
        this.gzcbService = gzcbService;
        this.httpSessionService = httpSessionService;
    }


    private static final Logger log = LoggerFactory.getLogger(GzcbController.class);


    //获取当前登录人所在机关检查科室集合 -公用部分
    @PostMapping("/getJcks")
    @ResponseBody
    public DataResult getJcks() {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        String substring = currentDeptId.substring(0, 9);
        LambdaQueryWrapper<GzcbEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(GzcbEntity::getJcks) // 只查分组字段
                .like(GzcbEntity::getJcksdm, substring)
                .groupBy(GzcbEntity::getJcks);
        List<GzcbEntity> list = gzcbService.list(queryWrapper);
        return DataResult.success(list);
    }


    @PostMapping("/queryGzcbData")
    @ApiOperation(value = "查询关注查补数据")
    @LogAnnotation(title = "重点关注", action = "关注查补")
    public DataResult queryGzcbData(@RequestBody GzcbEntity gzcbEntity) throws ParseException {
        IPage<GzcbEntity> iPage = gzcbService.queryGzcbData(gzcbEntity);
        return DataResult.success(iPage);
    }

    @PostMapping("/exportGzcbData")
    @ApiOperation(value = "查询关注查补数据")
    @LogAnnotation(title = "重点关注", action = "关注查补")
    public DataResult exportGzcbData(@RequestBody GzcbEntity gzcbEntity) throws ParseException {
        List<GzcbEntity> gzcbEntityList = gzcbService.exportGzcbData(gzcbEntity);
        return DataResult.success(gzcbEntityList);
    }

}